#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 26 21:46:13 2021

@author: liqingsimac
"""

#'''
###############################################
##布朗运动，样本路径的模拟
import numpy as np
import matplotlib.pyplot as plt

N=50
Y=np.random.randn(N) #独立同分布的随机数
R=np.zeros(N+1)
R[1:N+1]=np.cumsum(Y) #部分和
S=R/np.sqrt(N) 
t=np.linspace(0,1,N+1)

fig=plt.figure()
ax=fig.add_subplot(111)

ax.hlines(y=0,xmin=-0.2,xmax=1.2)
ax.vlines(x=0,ymin=-2,ymax=2)

ax.plot(t,S,'b-')
ax.set_xlabel('t = time')
ax.set_ylabel('S(t)')

#fig.savefig('bm-sample-path.png')